package cn.com.egova.demoapplication;

import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.view.View;
import android.view.animation.OvershootInterpolator;
import android.widget.Button;
import android.widget.ImageView;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import cn.com.egova.demoapplication.base.BaseActivity;
import cn.com.egova.demoapplication.tools.CustomInterpolator;

/**
 * 注意插值器里 * 2个重要的参数:
 * 输入参数:inupt,input从0--->1变化
 * 输出参数:fraction,动画的完成度,input经过某种算法后,Interpolator的getInterpolator()返回的值,
 * 当fraction为负数时,会向相反的方向执行动画.
 * dang
 */
public class InterpolatorActivity extends BaseActivity {

    @InjectView(R.id.btn_decelerate)
    Button btnDecelerate;
    @InjectView(R.id.btn_custom)
    Button btnCustom;
    @InjectView(R.id.iv)
    ImageView iv;
    private ObjectAnimator animator;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_interpolator);
        ButterKnife.inject(this);

        animator = ObjectAnimator.ofFloat(iv,"translationX",0f,400f);
        animator.setDuration(3000);
    }


    @Override
    public boolean isBackIconVisible() {
        return true;
    }

    @OnClick({R.id.btn_decelerate, R.id.btn_custom})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_decelerate:
//                animator.setInterpolator(new DecelerateInterpolator());             //减速插值器.
//                animator.setInterpolator(new AccelerateInterpolator());             //加速插值器.
//                animator.setInterpolator(new AccelerateDecelerateInterpolator());   //加速-减速-加速插值器.
//                animator.setInterpolator(new AnticipateInterpolator());             //开始的时从后向前甩.
//                animator.setInterpolator(new AnticipateOvershootInterpolator());    //开始时从后向前甩一小段距离,结束时向前弹出一定的值后回到原来的位置.
//                animator.setInterpolator(new BounceInterpolator());                 //动画结束时来回弹几下(测试机4下)最终停在结束的位置.
//                animator.setInterpolator(new CycleInterpolator(3));                 //循环播放,速率为正玄曲线.参数为循环播放的次数(在给定的during时间段内循环这么多次).
//                animator.setInterpolator(new LinearInterpolator());                 //线性(匀速)运动插值器.
                animator.setInterpolator(new OvershootInterpolator());                //向前弹出一定的值后回到原来的位置.
                animator.start();
                break;
            case R.id.btn_custom:
                animator.setInterpolator(new CustomInterpolator());      //使用自定义插值器.
                animator.start();
                break;
        }
    }
}
